﻿using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Lawn.AppServer
{
    public class Startup
    {
        private IConfiguration configuration;
        public Startup(IConfiguration configuration)
        {
            this.configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        {
             services.Configure<OptionsPort>(configuration.GetSection("ServerPort"));
             services.Configure<List<OptionsRemoteServer>>(configuration.GetSection("RemoteServer"));
            // var remoteServer = new RemoteServer("127.0.0.1", 1234);
            // remoteServer.TopicTypes.Add(new TopicType()
            // {
            //             
            //     Topic = "top2",
            //     Next = true,
            //     NextTopic = "reply_top1"
            // });
            //         
            // var remoteServer2 = new RemoteServer("127.0.0.1", 1233);
            // remoteServer2.TopicTypes.Add(new TopicType()
            // {
            //             
            //     Topic = "top1",
            //     Next = true,
            //     NextTopic = "reply_top1"
            // });
            // services.Configure<OptionsRemoteServer>(x =>
            // {
            //     x.Server.Add(remoteServer);
            //     x.Server.Add(remoteServer2);
            //             
            // }); 
                    
            services.Configure<HostOptions>(x =>
            {
                x.ShutdownTimeout = new TimeSpan(0, 0, 60);
            }); 
            services.AddHostedService<MqService>(); 
            services.AddDefaultSerializeProvider();
            services.AddMqService();
        }
    }
}